package containerlogistik.implementation;

import static containerlogistik.implementation.Values.*;
import containerlogistik.interfaces.Acceleration;
import containerlogistik.interfaces.Force;
import containerlogistik.interfaces.Level;
import containerlogistik.interfaces.Mass;

public class ForceInN extends AbstractValue<Force> implements Force {
    
    private final double nmeter;

    private ForceInN(double nmeter) {
        this.nmeter = nmeter;
    }

    static ForceInN valueOf(double nmeter) {
        return new ForceInN(nmeter);
    }

    @Override
    public double n() {
        return this.nmeter;
    }

    @Override
    public boolean isZero() {
        return (this.equals(Values.ZERO_FORCE));
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public String toString() {
        return String.format("ForceInN{nmeter=%.2f}",
                this.n());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (!(obj instanceof Force)) return false;
        return this.compareTo((Force)obj) == 0;
    }

    @Override
    public int hashCode() {
        return hashDouble(this.n());
    }

    @Override
    public int compareTo(Force o) {
        return Double.compare(this.n(), o.n());
    }

    @Override
    public Force add(Force value) {
        return forceInN(this.n() + value.n());
    }

    @Override
    public Force sub(Force value) {
        return forceInN(this.n() - value.n());
    }

    @Override
    public Force mul(double factor) {
        return forceInN(this.n() * factor);
    }

    @Override
    public Force div(double factor) {
        return forceInN(this.n() / factor);
    }

    @Override
    public Force inverse() {
        return forceInN(-this.n());
    }

    @Override
    public double div(Force value) {
        return (this.n() / value.n());
    }

    @Override
    public Force mul(Level value) {
        return this.mul(Math.signum(value.g()));
    }

    @Override
    public Acceleration div(Mass value) {
        return accelerationInMs2(this.n() / value.kg());
    }
    
}
